<?php
/**
 * header 头部
 * User: tengyu
 * Date: 2017/8/23
 * Time: 17:09
 */?>
<nav id="nav" class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <a href="/">
            <img class="mzj" src="{{asset('/img/logo_word.png')}}" alt="">
        </a>
        <ul class="nav navbar-nav navbar-right">
            @if(!session('user') || !is_object(session('user')))
                <li><a href="{{url('/login')}}">登录</a></li>
                <li><a style="padding:15px 15px;" href="{{url('/register')}}">注册</a></li>
                @else
                <li><a href="javascript:void(0);">{{$user->name}}</a></li>
                <li><a href="{{url('/loginout')}}">注销</a></li>
                <li><a href="{{asset('/user')}}"><img class="person" src="{{asset('/img/personyellow.png')}}">个人中心</a></li>
            @endif
            <!--购物车弹窗-->
            @if(session('user'))
            <li class="dropdown">
                <a href="{{url('/shopcar')}}" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                    <img src="{{asset('/img/car.png')}}" alt="">
                    <span class="badge">{{count($param['cart']['cartlist'])}}</span>
                </a>
                <!--弹窗-->
                @if(count($param['cart']['cartlist'])>0)
                <?php  $common_colors = array();
                $common_colors = [
                    '1'=>'/img/color/1.png',
                    '2'=>'/img/color/2.png',
                    '3'=>'/img/color/3.png',
                    '4'=>'/img/color/4.png',
                    '5'=>'/img/color/5.png',
                    '6'=>'/img/color/6.png',
                    '7'=>'/img/color/7.png',
                    '8'=>'/img/color/8.png',
                    '9'=>'/img/color/9.png'];
                ?>
                <div id="propCar" class="dropdown-menu">
                    <p>购物车 (<span>{{count($param['cart']['cartlist'])}}</span>)</p>
                    <?php $rent_type['1'] = 'details_nimbleprice';$rent_type['2'] = 'details_fixprice';?>
                    @foreach($param['cart']['cartlist'] as $v)
                    <ul class="carList">
                        <input type="hidden" name="common_cartid" value="{{$v->cart_id}}">
                        <input type="hidden" name="comm_cartnum" value="{{$v->cart_fitment_num}}">
                        <li>
                            @if($v->cart_status==1)
                            <img src="{{asset('/img/checked.jpg')}}" class="checkAlls" onclick="common_cart_dt_select(this.alt,{{$v->cart_id}})" alt="checked.jpg">
                            @else
                            <img class="checkAlls" src="{{asset('/img/choose.png')}}" onclick="common_cart_dt_select(this.alt,{{$v->cart_id}})" alt="choose.png">
                            @endif
                            <div class="media">
                                <div class="media-left"><img src="{{asset(env('STATIC_FILE_ERP_PATH').$v->fitment_details_imgMaster)}}" style="width:151px;height:92px "></div>
                                <div class="media-body">
                                    <p>
                                        <span>欧尚办公组合家具欧尚办公组合家具欧尚办公组合家具欧尚办公</span>
                                        <i class="pull-right" onclick="common_deletecart({{$v->cart_id}})">&times;</i>
                                    </p>
                                    <p>
                                        <img color src="{{asset($common_colors[$v->color_type])}}" alt="颜色类型图片">
                                        <u class="pull-right">
                                            <b class="glyphicon glyphicon-minus-sign" onclick="comm_decrement({{$v->cart_id}},{{$v->cart_fitment_num}})"></b>
                                            <span>{{$v->cart_fitment_num}}</span>
                                            <b class="glyphicon glyphicon-plus-sign" onclick="comm_increment({{$v->cart_id}},{{$v->cart_fitment_num}})"></b>
                                        </u>
                                    </p>
                                    <p>
                                        <span class="active data">@if($v->cart_rent_type==1){{'12个月'}}@else{{'18个月'}}@endif</span>
                                        <span class="pull-right">¥{{$v->$rent_type[$v->cart_rent_type]}}/月</span>
                                    </p>
                                </div>
                            </div>
                        </li>
                    </ul>
                    @endforeach
                    <div class="bottomPay">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-xs-6">
                                    <img style="margin-bottom: 2px;" src="{{asset('/img/checked.jpg')}}" alt="">
                                    已选择<span>{{count($param['cart']['cartlist_status'])}}</span>件商品
                                </div>
                                <div class="col-xs-6">
                                    应付总额：<span style="color:#B84540;">¥{{$param['cart']['countprice']}}</span>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-xs-6">
                                    共计<span>{{$param['cart']['countnum']}}</span>件商品
                                </div>
                                <div class="col-xs-6">
                                    应付总额不包含运费
                                </div>
                            </div>
                        </div>
                        <div class="container-fluid">
                            <a href="{{url('/shopcart')}}">
                                <button class="btn btn-success">购物车查看</button>
                            </a>
                            <a href="{{url('/confirmorder')}}">
                                <button class="btn btn-warning">立即付款</button>
                            </a>
                        </div>
                    </div>
                </div>
                    @else
                    <div id="propCar" class="dropdown-menu" style="height:160px;">
                        <div class="container-fluid">
                            <p class="text-center" style="color:#333;line-height:80px;" ><img class="noShopping" src="{{asset('/img/791509095234_.pic.jpg')}}" alt="购物车中还没有商品，赶紧选购吧"></p>
                        </div>
                    </div>
                @endif
            </li>
            @endif
        </ul>
    </div>
</nav>
<script>
    /**购物车删除*/
    function common_deletecart(cartid)
    {
        $.ajax({
            url:'/shopcart/delete/'+cartid,
            type:'post',
            headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
            data:{'id':cartid},
            dataType:'json',
            success:function(res){
                if(res.res=='ok'){
                    history.go(0);
                }else{
                    console.log(res);
                }
            }
        });
    }
    /**购物车编辑*/
    function comm_decrement(cartid,num){
        if(parseInt(num)>1){
            num--;
            common_cartedit(cartid,num);
        }else{
            common_deletecart(cartid);
        }
    }
    function comm_increment(cartid,num){
        num++;
        common_cartedit(cartid,num);
    }

    function common_cartedit(id,num)
    {
        $.ajax({
            url:'/shopcart/edit/'+id,
            type:'post',
            headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
            dataType:'json',
            data:{'num':num},
            success:function(res){
                if(res.res=='ok'){
                    $("#propCar ul.pull-right span").html(num);
                    history.go(0);
                }else{
                    console.log(res);
                }
            }
        });
    }
    /**
     * 购物车选中详情，默认都选
     * checked.jpg 没选支付
     * choose.png 选择
     */
    function common_cart_dt_select(imgName,cart_id)
    {
        var cart_status = '';
        if(imgName=='checked.jpg'){
            cart_status = '0';
        }else{
            cart_status = '1';
        }
        $.ajax({
            url:'/shopcart/edit/'+cart_id,
            type:'post',
            headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
            data:{'id':cart_id,'cart_status':cart_status},
            dataType:'json',
            success:function(res)
            {
                if(res.res=='ok'){
                    history.go(0);
                }else{
                    console.log(res);
                }
            }
        });
    }
</script>
